﻿/* Author: Tomer Paz
   games.com
   2009
*/

/* data object for server broadcasts */

package monopoly.ServerBroadcast {
	
	import fl.events.*;
	import flash.events.*;
	import fl.controls.TextArea;
	import fl.events.ComponentEvent; 
	import fl.controls.ScrollPolicy;
	import fl.containers.ScrollPane;
	import flash.events.EventDispatcher;
	import flash.display.Stage;
	import monopoly.views.TitlePane;
	import monopoly.IFS.GLOBALS;
	import monopoly.Localization.*;
	
	public class ServerBroadcast extends ScrollPane
		{
		protected var _logArea:TextArea;
		protected var _Title:TitlePane;
		
		public function ServerBroadcast()
			{
			// position ourselves
			this.x = 0;
			this.y = 0;
			
			/* setup components */
			
			setupTitle();
			
			setupLogArea();
			}
			
		/* public interface */
		
		// reserve "name" for different future server names...
		public function WriteMessage(name:String, msg:String):void
			{
			// if not the first line	
			if ( _logArea.length )
				{
				_logArea.appendText("\r\n");
				}

			_logArea.appendText(msg);
			}
		public function get logArea():TextArea
			{
			return _logArea;
			}
			
		public override function set height(value:Number):void
			{
			super.height = value;
			_logArea.setSize(_logArea.width, value - _Title.height - GLOBALS.VPADDING*6 + 3);
			_logArea.drawNow();
			}

		public override function set width(value:Number):void
			{
			super.width = value;
			_logArea.width = value - 1;
			_Title.width = value - 1;
			}
					
		/* Private area */
		
		private function setupTitle():void
			{
			var myString:ILocalLanguage = LocalLanguage.getInstance();
			_Title = new TitlePane(myString.ActionsHistory);
			_Title.x = 1;
			_Title.y = 3;
			
			addChild(_Title);
			}
		
		private function setupLogArea():void
			{
			_logArea = new TextArea();
			
			_logArea.height = 0;
			_logArea.width  = 0;	
			_logArea.editable = false;
			//_logArea.graphics.beginFill(GLOBALS.DEFAULT_OFFWHITE_BG);
			//_logArea.graphics.endFill();
			_logArea.x = 0;
			_logArea.y = _Title.y + _Title.height;
			addChild(_logArea);
			}
		}
}